package com.zq.designpaterns.behavior.iterator;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2021/01/14  11:08
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
public class NameRepository implements Container {
    public static final String[] names = {"Robert", "John", "Julie", "Lora"};


    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private static class NameIterator implements Iterator {
        int index;

        @Override
        public boolean hasNext() {
            return index < names.length;
        }

        @Override
        public Object next() {
            return this.hasNext() ? names[index++] : null;
        }
    }
}
